package com.jerkin.handler;

import com.jerkin.invoke.InvokeMethod;
import com.jerkin.request.RpcRequest;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

/**
 * @version V1.0
 * @ClassName: RpcServerHandler
 * @Description:
 * @author: huhongzhi
 * @date: 2021/4/22 23:36
 */
@ChannelHandler.Sharable
public class RpcServerHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        System.out.println("服务端获取的rpc的信息:" + msg);
        RpcRequest rpcRequest = (RpcRequest) msg;
        Object object = InvokeMethod.invoke(rpcRequest);
        System.out.println("获取得结果:"+object.toString());
        ctx.writeAndFlush(object);
    }
}
